function( add_debug_definitions CurrentTarget)
	set (debug_compile_definitions "TT_DEBUG")

	get_target_property(current_compile_definitions ${CurrentTarget} COMPILE_DEFINITIONS_DEBUG)
	if(current_compile_definitions)
		set(debug_compile_definitions
			${debug_compile_definitions}
			${current_compile_definition}
		)
	endif()

	set_target_properties(${CurrentTarget}
		PROPERTIES
		COMPILE_DEFINITIONS_DEBUG "${debug_compile_definitions}"
	)
endfunction()

function( add_platform_definitions CurrentTarget)
	if(WIN32)
		set (platform_compile_definitions "TT_WIN32")
	elseif(APPLE)
		set (platform_compile_definitions "TT_MACOS")
	elseif(UNIX)
		set (platform_compile_definitions "TT_UNIX")
	endif()

	set ( platform_compile_definitions
		${platform_compile_definitions}
		"BOOST_AUTO_LINK_TAGGED"
	)

	get_target_property(current_compile_definitions ${CurrentTarget} COMPILE_DEFINITIONS)
	if(current_compile_definitions)
		set(platform_compile_definitions
			${platform_compile_definitions}
			${current_compile_definition}
		)
	endif()

	set_target_properties(${CurrentTarget}
		PROPERTIES
		COMPILE_DEFINITIONS "${platform_compile_definitions}"
	)
endfunction()

function(add_compiler_flags CurrentTarget)
#	message(${CMAKE_CXX_FLAGS})
#	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
#	add_definitions(/W4)
    if(CMAKE_COMPILER_IS_GNUCXX)
        IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
            #get_target_property(CurrentTargetCompileFlags ${CurrentTarget} COMPILE_FLAGS)
            set(CurrentTargetCompileFlags "${CurrentTargetCompileFlags} -fPIC")
            SET_TARGET_PROPERTIES(${CurrentTarget} PROPERTIES COMPILE_FLAGS ${CurrentTargetCompileFlags})
        ENDIF()
    endif()
endfunction()

macro(add_compiler_flags_global)
    if(MSVC)
	
		foreach (flag_var
             CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
             CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)

			 string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")

			# Replaces /W3 with /W4 in defaults.
			string(REPLACE "/W3" "-W4 -WX" ${flag_var} "${${flag_var}}")
		endforeach()
	
		# string(REGEX REPLACE "/W3" "/W4 /WX" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
		# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
		# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
		# CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
    endif()
    if(CMAKE_COMPILER_IS_GNUCXX)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
    endif()
endmacro()

function(add_compile_definitions CurrentTarget)
	add_platform_definitions(${CurrentTarget})
	add_debug_definitions(${CurrentTarget})
	add_compiler_flags(${CurrentTarget})
endfunction()
